package com.haiwei.poi.word.manager;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.UUID;

public final class ImageUtil {

    public static File convert(File file, String type) throws Exception {
        try {
            if (file.canRead()) {
                BufferedImage src = ImageIO.read(file);
                File temp = new File(UUID.randomUUID() + "-image-convert-temp." + type);
                ImageIO.write(src, type, temp);
                return temp;
            }
            return null;
        } finally {
            if(file != null ){
                file.deleteOnExit();
            }
        }
    }
}
